package com.laijiale.controller;

import com.laijiale.constant.ML;
import com.laijiale.constant.RE;
import com.laijiale.dto.CourseInsertDTO;
import com.laijiale.dto.CoursePageDTO;
import com.laijiale.dto.CourseUpdateDTO;
import com.laijiale.dto.EpisodeExcelDTO;
import com.laijiale.entity.Course;
import com.laijiale.result.Result;
import com.laijiale.service.CourseService;
import com.laijiale.until.EasyExcelUtil;
import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.laijiale.entity.Course;
import com.laijiale.service.CourseService;
import org.springframework.web.multipart.MultipartFile;
import vo.CourseSimpleListVO;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课程表 控制层。
 *
 * @author laijiale
 * @since 2024-12-22
 */
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private CourseService courseService;


    @Operation(summary ="新增－ 单条",description ="新增一条课程记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody CourseInsertDTO dto) {
        return courseService.insert(dto);
    }
    @Operation(summary="查询－ 单条",description="按主键查询一条课程记录")
    @GetMapping("select/{id}")
    public Course select(@PathVariable("id") Long id) {
        return courseService.select(id);
    }
    @Operation(summary ="查询－ 简单全查",description="查询全部课程记录")
    @GetMapping("simpleList")
    public List<CourseSimpleListVO> simpleList() {
        return courseService.simpleList();
    }
    @Operation(summary="查询－ 分页",description ="分页查询课程记录")
    @GetMapping("page")
    public Page<Course> page(@Validated CoursePageDTO dto) {
        return courseService.page(dto);
    }

    @Operation(summary="修改－单条",description ="按主键修改一条课程记录")
    @PutMapping("update")
    public boolean update(@RequestBody CourseUpdateDTO dto) {
        return courseService.update(dto);
    }
    @Operation(summary="删除－ 单条",description="按主键删除一条课程记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return courseService.delete(id);
    }
    @Operation(summary="删除－ 批量",description ="按主键批量删除课程记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return courseService.deleteBatch(ids);
    }
    @Operation(summary="修改 - 修改课程摘要",description ="修改课程摘要")
    @PostMapping("uploadSummary/{id}")
    public Result<String> uploadSummary(MultipartFile summaryFile, @PathVariable("id") Long id){
        return courseService.uploadSummary(summaryFile, id);
    }
    @Operation(summary="修改 - 修改课程封面",description ="修改课程封面")
    @PostMapping("uploadCover/{id}")
    public Result<String> uploadCover(MultipartFile coverFile, @PathVariable("id") Long id){
        return courseService.uploadCover(coverFile, id);
    }


}